package com.ruoyi.teacher.service.impl;

import java.util.List;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.system.api.RemoteUserService;
import com.ruoyi.system.api.domain.SysUser;
import com.ruoyi.teacher.dto.TeacherDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.teacher.mapper.TTeacherMapper;
import com.ruoyi.teacher.domain.TTeacher;
import com.ruoyi.teacher.service.ITTeacherService;

/**
 * 教师管理Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-12-24
 */
@Service
public class TTeacherServiceImpl implements ITTeacherService 
{
    @Autowired
    private TTeacherMapper tTeacherMapper;

    @Autowired
    private RemoteUserService remoteUserService;

    /**
     * 查询教师管理
     * 
     * @param id 教师管理主键
     * @return 教师管理
     */
    @Override
    public TTeacher selectTTeacherById(Long id)
    {
        return tTeacherMapper.selectTTeacherById(id);
    }

    /**
     * 查询教师管理列表
     * 
     * @param tTeacher 教师管理
     * @return 教师管理
     */
    @Override
    public List<TTeacher> selectTTeacherList(TTeacher tTeacher)
    {
        return tTeacherMapper.selectTTeacherList(tTeacher);
    }

    /**
     * 新增教师管理
     * 
     * @param tTeacher 教师管理
     * @return 结果
     */
    @Override
    public int insertTTeacher(TTeacher tTeacher)
    {
        return tTeacherMapper.insertTTeacher(tTeacher);
    }

    /**
     * 修改教师管理
     * 
     * @param tTeacher 教师管理
     * @return 结果
     */
    @Override
    public int updateTTeacher(TTeacher tTeacher)
    {
        return tTeacherMapper.updateTTeacher(tTeacher);
    }

    /**
     * 批量删除教师管理
     * 
     * @param ids 需要删除的教师管理主键
     * @return 结果
     */
    @Override
    public int deleteTTeacherByIds(Long[] ids)
    {
        return tTeacherMapper.deleteTTeacherByIds(ids);
    }

    /**
     * 删除教师管理信息
     * 
     * @param id 教师管理主键
     * @return 结果
     */
    @Override
    public int deleteTTeacherById(Long id)
    {
        return tTeacherMapper.deleteTTeacherById(id);
    }

    @Override
    public List<TTeacher> findTeacherByType(String type) {
        return tTeacherMapper.findTeacherByType(type);
    }
    // 根据老师名字查询
    @Override
    public TTeacher findTeacherByName(String name) {
        return tTeacherMapper.findTeacherByName(name);

    }

    @Override
    public String addTeacher(TeacherDto teacherDto) {
        TTeacher tTeacher = new TTeacher();
        tTeacher.setName(teacherDto.getUserName());
        tTeacher.setPhone(teacherDto.getPhonenumber());
        tTeacher.setType(teacherDto.getTeacherType());
        tTeacher.setSex(teacherDto.getSex());
        insertTTeacher(tTeacher);
        return "添加成功";
    }

    @Override
    public List<SysUser> getNoBindUserList() {
        AjaxResult noBindUserList = remoteUserService.getNoBindUserList();
        Object data = noBindUserList.get("data");
        List<SysUser> sysUsers = JSONObject.parseArray(JSON.toJSONString(data), SysUser.class);
        return sysUsers;
    }

}
